<?php
//格式化商品分类列表for商品分类选择
if (!function_exists('formatGoodCateList')) {
    function formatGoodCateList($arr) {
        $return = [];
        $i = 0;
        foreach ($arr as $key=>$value) {
            if ($value['parent_id'] == -1) {
                $return[$i] = ['title'=>$value['name'],'id'=>$value['id'],'type'=>'group'];
                $j = 0;
                foreach ($arr as $k=>$v) {
                    if ($v['parent_id'] == $value['id']) {
                        $return[$i]['child'][$j] = ['title'=>$v['name'],'id'=>$v['id']];
                        $j++;
                    }
                }
                $i++;
            }
        }
        return $return;
    }
}
//返回商品分类名
if (!function_exists('getCateName')) {
    function getCateName($id, $arr) {
        $cateName = '';
        foreach ($arr as $k=>$v) {
            if ($v['id'] == $id) {
                $cateName = $v['name'];
                break;
            }
        }
        return $cateName;
    }
}
//返回商品分类ID
if (!function_exists('getCateId')) {
    function getCateId($name, $arr) {
        $cateId = 0;
        foreach ($arr as $k=>$v) {
            if ($v['name'] == $name) {
                $cateId = $v['id'];
                break;
            }
        }
        return $cateId;
    }
}
